package Demo07;
/*
字符串-->转换；
public chat[] toCharArray();字符串拆分为字符数组
public byte[] getBytes();获取当前字符串底层的字节数组
public String replace(CharSequence oldString,CharSequence newString);老字符串，替换成新字符串

 */
public class Demo03StringConvert {
    public static void main(String[] args) {
        char[] chars = "helloworld".toCharArray();
        System.out.println(chars[2]);//l
        System.out.println(chars.clone()); //helloworld
        System.out.println("长度；"+chars.length);//长度；10
        System.out.print("{");
        for (int i = 0; i < chars.length; i++) {
            if (i==chars.length-1){
                System.out.println(chars[i]+"}");
            }else {
                System.out.print(chars[i]+"^"); //{h^e^l^l^o^w^o^r^l^d}
            }
        }

        //转字节数组；
        byte[] bytes = "ABCDEXYZ".getBytes();
        System.out.println(bytes); //[B@67b6d4ae
        for (int i = 0; i < bytes.length; i++) {
            System.out.print(bytes[i]+"\t"); //65	66	67	68	69	88	89	90
        }
        System.out.println("\n=========\n");

        //替换方法；
        String str1= "How do you do?";
        String str2 = str1.replace("o", "*");
        System.out.println(str1); //How do you do?
        System.out.println(str2); //H*w d* y*u d*?
        String replace = str1.replace("d", "^");//How ^o you ^o?
        System.out.println(replace);


    }
}
